// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

@use '../vars/lib' as *;

$max-footer-content-width: $content-max;

@mixin divider-line {
    border-bottom: $border-width solid $m24-color-light-gray;
}

// whole footer
.moz24-footer {
    @include invert-colors;
    background-color: $m24-color-alt-white;
    color: $m24-color-black;
    padding-top: $spacer-xl;

    *:focus,
    *:focus-visible {
        outline-offset: $spacer-2xs;
    }
}

// main content
.moz24-footer-content {
    @include container;
    margin: 0 auto;
    padding-bottom: $container-padding
}

// primary nav
.moz24-footer-primary {
    margin: $spacer-lg 0;
    display: flex;
    flex-direction: column;

    @media #{$mq-lg} {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
    }
}

.moz24-footer-sections-container {
    display: flex;
    flex-direction: column;
    gap: $spacer-lg;
    width: 100%;

    @media #{$mq-lg} {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
        gap: $grid-gutter;
    }

    @media #{$mq-xl} {
        gap: grid(1);
    }
}

.moz24-footer-advertising {
    @include divider-line;
    padding-bottom: $spacer-lg;
    width: 100%;

    @media #{$mq-lg} {
        max-width: 343px;
        border-bottom: transparent;
    }

    h2 {
        color: $m24-color-black;
    }
}

.moz24-footer-advertising-wrapper {
    width: 100%;
}

.moz24-footer-advertising-logo {
    max-width: 250px;
}

.moz24-footer-advertising-link {
    font-weight: 600;
    background-color: $m24-color-alt-white;
    padding: 8px 24px;
    border: $border-width solid $m24-color-black;
    text-align: center;
    margin-top: $spacer-lg;
    display: block;

    @media #{$mq-sm} {
        width: fit-content;
    }

    &:link,
    &:visited {
        color: $m24-color-black;
        text-decoration: none;
    }

    &:active,
    &:hover,
    &:focus,
    &:focus-visible {
        background-color: $m24-color-alt-black;
        color: $m24-color-white;

        .mzp-c-button-icon-end path {
            fill: $m24-color-white;
        }

        .mzp-c-button-icon-text {
            color: $m24-color-white;
        }
    }

    .mzp-c-button-icon-text span {
        @include visually-hidden;
    }
}

.moz24-footer-links {
    @include divider-line;

    @media #{$mq-xs} {
        display: grid;
        grid-template-rows: 1fr 1fr;
        grid-template-columns: 1fr 1fr;
        column-gap: $grid-gutter;
        place-items: stretch start;
    }

    @media #{$mq-sm} {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: start;
        gap: grid(1);
    }

    @media #{$mq-lg} {
        justify-content: flex-end;
        border-bottom: transparent;
        width: 100%;
        gap: $grid-gutter;

        section {
            width: calc((100% - 3 * $grid-gutter) / 3);
        }
    }
}

.moz24-footer-socials {
    @include divider-line;

    @media #{$mq-lg} {
        border-bottom: transparent;
    }
}

.moz24-footer-refresh-social-wrapper {
    display: flex;
    align-items: center;
    margin-bottom: 32px;

    @media #{$mq-md} {
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;
    }

    @media #{$mq-lg} {
        align-items: flex-end;
    }
}


.moz24-footer-heading-social {
    padding: 0;
    font-family: var(--body-font-family);
    color: $m24-color-black;
    margin: 0;
    font-size: $text-body-sm;
    font-weight: 400;

    @media #{$mq-md} {
        margin-bottom: $spacer-sm;
    }
}

.moz24-footer-social-links {
    margin: 0 0 0 $spacer-lg;
    display: flex;
    background-color: #161616; // hard-coded value as a fallback for readability on older browsers

    @media #{$mq-md} {
        margin: 0;
    }

    li {
        margin-right: $spacer-2xs;
        display: inline-block;

        &:last-of-type {
            @include bidi(((margin-right, 0, 0), (margin-left, 0, 0)));
        }

        a {
            @include bidi(((margin-right, 8px, 0), (margin-left, 0, 8px)));
            @include image-replaced;
            background-repeat: no-repeat;
            background-size: 16px 16px;
            background-position: center center;
            opacity: .45;
            border-bottom: 1px solid rgba(0,0,0,0);
            display: block;
            height: 24px;
            width: 24px;

            &:last-of-type {
                @include bidi(((margin-right, 0, 0), (margin-left, 0, 0)));
            }

            &:hover,
            &:focus {
                opacity: 1;
                border-bottom-color: transparent;
            }

            &.linkedin {
                background-image: url('/media/protocol/img/icons/social/linkedin/white.svg');
            }

            &.tiktok {
                background-image: url('/media/protocol/img/icons/social/tiktok/white.svg');
            }

            &.spotify {
                background-image: url('/media/protocol/img/icons/social/spotify/white.svg');
            }

            &.twitter {
                background-image: url('/media/protocol/img/icons/social/x/white.svg');
            }

            &.bluesky {
                background-image: url('/media/img/icons/social/bluesky/white.svg');
            }

            &.instagram {
                background-image: url('/media/protocol/img/icons/social/instagram/white.svg');
            }

            &.youtube {
                background-image: url('/media/protocol/img/icons/social/youtube/white.svg');
            }
        }
    }
}

.moz24-footer-label {
    color: $m24-color-mid-gray;
    font-size: $text-body-sm;
    font-weight: 600;
    @include bidi(((margin-right, 8px, 0), (margin-left, 0, 8px)));
}

.moz24-footer-primary-list {
    li {
        padding-bottom: $spacer-xs;
    }

    a,
    a:link,
    a:visited {
        text-decoration: none;
        position: relative;
        color: $m24-color-black;
        font-weight: 400;
    }

    a:hover,
    a:link:hover,
    a:visited:hover {
        color: $m24-color-black;

        &::after {
            display: block;
            content: "";
            position: absolute;
            width: 100%;
            height: 1px;
            left: 0;
            bottom: 1px;
            background: $m24-color-black;
        }
    }

    a:focus-visible,
    a:link:focus-visible,
    a:active,
    a:link:active {
        color: $m24-color-black;

        &::after {
            display: none;
        }
    }
}

// actions section
.moz24-footer-actions {
    @include divider-line;
    padding-bottom: $spacer-lg;
    margin-bottom: $spacer-lg;
    display: flex;
    flex-direction: column;
    position: relative;

    @media #{$mq-md} {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    @media #{$mq-lg} {
        justify-content: flex-end;
        gap: $grid-gutter;
    }
}

// donation link
.moz24-footer-donate {
    position: relative;
    border-radius: 0;
    font-weight: 600;
    background-color: $m24-color-alt-white;
    padding: 8px 24px;
    border: $border-width solid $m24-color-black;
    text-align: center;
    max-width: 800px;
    margin-bottom: $spacer-lg;

    @media #{$mq-md} {
        margin-bottom: 0;
    }

    &:link,
    &:visited {
        color: $m24-color-black;
        text-decoration: none;
    }

    &:active,
    &:hover,
    &:focus,
    &:focus-visible {
        background-color: $m24-color-alt-black;
        color: $m24-color-white;

        .mzp-c-button-icon-start path {
            fill: $m24-color-white;
        }

        .mzp-c-button-icon-text {
            color: $m24-color-white;
        }
    }
}


// language form
.moz24-c-language-switcher {
    position: relative;

    &:has(.mzp-js-language-switcher-select:hover)::before,
    &:has(.mzp-js-language-switcher-select:focus)::before,
    &:has(.mzp-js-language-switcher-select:focus-within)::before {
        background: $m24-color-alt-black url('/media/protocol/img/icons/globe.svg') center center no-repeat;
        background-size: 16px 16px;
    }

    &::before {
        @include bidi(((left, 4px, auto), (right, auto, 4px)));
        background: transparent url('/media/protocol/img/icons/globe-white.svg') center center no-repeat;
        background-size: 16px 16px;
        top: 50%;
        margin-top: -16px;
        content: "";
        display: block;
        height: 32px;
        width: 32px;
        position: absolute;
    }

    label {
        @include visually-hidden;
    }

    .mzp-c-language-switcher-link {
        color: $m24-color-black;
        position: absolute;
        top: -1.5em;

        .js & {
            @include visually-hidden;
        }

        &:focus,
        &:focus-visible {
            clip: auto;
            height: auto;
            overflow: visible;
            text-indent: 0;
            width: auto;
        }
    }

    .mzp-js-language-switcher-select {
        @include bidi(((background-position, right 8px center, 8px center),));
        background: $m24-color-alt-white url('/media/protocol/img/icons/caret-down-white.svg') no-repeat;
        background-size: 16px 16px;
        border-radius: 0;
        border: $border-width solid $m24-color-alt-black;
        color: $m24-color-alt-black;
        font-weight: 600;
        padding-left: 36px;
        max-width: 100%;
        width: 100%;
        margin: 0;

        @media #{$mq-lg} {
            width: fit-content;
        }

        &:hover,
        &:focus,
        &:focus-visible,
        &:focus-within {
            color: $m24-color-white;
            background: $m24-color-alt-black url('/media/protocol/img/icons/caret-down.svg') no-repeat;
            @include bidi(((background-position, right 8px center, 8px center),));
            background-size: 16px 16px;
        }
    }
}

// secondary nav
.moz24-footer-secondary {
    position: relative;
    margin: $spacer-lg 0;
    line-height: 1.5;
}

.moz24-footer-legal {
    display: flex;
    flex-direction: column;
    color: $m24-color-black;
    font-size: 12px;

    @media #{$mq-lg} {
        flex-direction: row;
        justify-content: space-between;
        font-size: 14px;
    }
}

.moz24-footer-license {
    @media #{$mq-md} {
        max-width: unset;
        @include bidi(((margin-right, 10%, 0), (margin-left, 0, 10%)));
    }

    @media #{$mq-lg} {
        margin-bottom: 0;
    }

    a {
        display: inline-block;
    }

    a,
    a:link,
    a:visited {
        color: $m24-color-black;
        font-weight: 600;
    }
}

.moz24-footer-terms {
    margin-bottom: 0;

    li {
        padding-inline-end: $spacer-md;
        margin-bottom: $spacer-xs;

        @media #{$mq-md} {
            display: inline-block;
        }

        &:last-of-type {
            margin-bottom: 0;
        }
    }

    a,
    a:link,
    a:visited {
        color: $m24-color-black;
        font-weight: 600;
    }
}

.moz24-footer-logo-image-bottom {
    width: 100%;
}
